﻿@{
    ViewBag.Title = "ArrangeWork";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style>
    #zls {
        width: 180px;
    }

    @@media screen and (max-width:1000px) {
        #zls {
            width: 100px;
        }
    }
</style>
<script>
    var Editing_ysList = []; //编辑域中的人员
    $(function () {
        init();
        gridList();
        $('#zls').click(function () {
            var initIdSelected = "";
            $.each(Editing_ysList,
                function () {
                    initIdSelected += this.id + ",";
                });
            $.modalOpen({
                id: "StaffCorrelation",
                title: "选择治疗师",
                url: "/SystemManage/SysStaff/Selector?single=true&isContansChildOrg=false&callbackType=json&dutyCode=RehabDoctor&initIdSelected=" + initIdSelected,
                showleftlalbel: false,
                width: "650px",
                height: "570px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick(function (data) {
                        staffTreeCallback(data);
                    });
                }
            });
        });
    });

    function init() {
        var date = new Date;
        //年份
        $("#Year").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                if (top.clients.yearArr && top.clients.yearArr.length) {
                    $.each(top.clients.yearArr, function () {
                        resultObjArr.push({ id: this, text: this });
                    });
                }
                return resultObjArr;
            },
            selectedValue: 1900 + date.getYear(),
        });
        //月份
        $("#Month").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                if (top.clients.monthArr && top.clients.monthArr.length) {
                    $.each(top.clients.monthArr, function () {
                        resultObjArr.push({ id: this, text: parseInt(this) < 10 ? "0" + this : this });
                    });
                }
                return resultObjArr;
            },
            selectedValue: date.getMonth() + 1,
        });
    }

    function gridList() {
        var $gridList = $("#HisgridList");
        $gridList.dataGrid({
            url: "/TherapeutistManage/TherapeutistCompleteList/GetpbGridJson",
            shrinkToFit: true,
            width: $("#tabGrid").width() - 2,
            postData: getSearchPostData(),
            height: $(window).height() - 185,
            colModel: [
                { label: "主键", name: "Id", hidden: true, key: true },
                { label: '姓名', name: 'Name', width: 150, align: 'left' },
                { label: '工号', name: 'ysgh', width: 150, align: 'left' },
                { label: '年份', name: 'year', width: 80, align: 'left' },
                {
                    label: '月份', name: 'month', width: 50, align: 'left', formatter: function (cellvalue) {
                        return parseInt(cellvalue) < 10 ? "0" + cellvalue : cellvalue
                    }
                },
                { label: '天数', name: 'ts', align: 'left' }
            ],
            pager: "#gridPager",
            sortname: 'year,month desc',
            rowNum: '10',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam',
                {
                    postData: getSearchPostData(),
                    url: "/TherapeutistManage/TherapeutistCompleteList/GetpbGridJson"
                }).trigger('reloadGrid');
        });
    }

    function getSearchPostData() {
        var postData = {};
        postData.year = $('#Year').val();
        postData.month = $('#Month').val();
        postData.ysgh = "";
        if (!postData.year || !postData.month) {
            return;
        }
        if (Editing_ysList.length > 0) {
            postData.ysgh = Editing_ysList[0].gh;
        }
        return postData;
    }

    //人员树 选择 回调
    function staffTreeCallback(treeSeleData) {
        Editing_ysList = [];
        var zlsNames = "";
        $.each(treeSeleData, function () {
            zlsNames += this.text + ",";
            Editing_ysList.push({ id: this.id, gh: this.value, Name: this.text, ks: this.Ex1, ksmc: this.Ex2 });
        })
        if (zlsNames.length > 0) {
            zlsNames = zlsNames.substring(0, zlsNames.length - 1);
        }

        $('#zls').val(zlsNames);
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "添加排班",
            url: "/TherapeutistManage/TherapeutistCompleteList/AddArrange",
            width: "600px",
            height: "600px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    //编辑
    function btn_edit() {
        var seleRowid = jQuery("#HisgridList").jqGrid("getGridParam", "selrow");
        if (!(seleRowid)) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        var Id = $("#HisgridList").jqGridRowValue().Id;
        $.modalOpen({
            id: "Form",
            title: "编辑",
            url: "/TherapeutistManage/TherapeutistCompleteList/EditArrange?keyvalue=" + Id,
            width: "550px",
            height: "300px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    //删除
    function btn_delete() {
        var seleRowid = jQuery("#HisgridList").jqGrid("getGridParam", "selrow");
        if (!(seleRowid)) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        var Id = $("#HisgridList").jqGridRowValue().Id;
        $.deleteForm({
            url: "/TherapeutistManage/TherapeutistCompleteList/DelArrange",
            param: { keyvalue: Id },
            success: function () {
                $("#HisgridList").trigger("reloadGrid");
            }
        });
    }

    //详情
    function btn_details() {
        var seleRowid = jQuery("#HisgridList").jqGrid("getGridParam", "selrow");
        if (!(seleRowid)) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        var count = $("#HisgridList").getGridParam("reccount");
        if (count === 0) {
            $.modalAlert("未选中行", 'warning');
            return;
        }
        var Id = $("#HisgridList").jqGridRowValue().Id;
        $.modalOpen({
            id: "Details",
            title: "查看",
            url: "/TherapeutistManage/TherapeutistCompleteList/EditArrange?keyvalue=" + Id,
            width: "550px",
            height: "570px",
            btn: null
        });
    }
    function btn_single() {
        $.modalOpen({
            id: "Form",
            title: "新建",
            url: "/TherapeutistManage/TherapeutistCompleteList/EditArrange",
            width: "550px",
            height: "300px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
</script>
<form id="form1">
    <div class="topPanel">
        <div class="toolbar" style="padding-left:30px">
            <div class="btn-group">
                <a id="NF-add" class="btn btn-primary dropdown-text" href="javascript:void()" onclick="btn_single()"><i class="fa fa-plus"></i>新建</a>
                <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                <ul class="dropdown-menu pull-right">
                    <li><a id="NF-add" authorize="yes" onclick="btn_add()" href="javascript:void()">批量新建</a></li>
                    <li><a id="NF-add" authorize="yes" onclick="btn_single()" href="javascript:void()">单独新建</a></li>
                </ul>
            </div>
            <div class="btn-group">
                <a id="NF-edit" class="btn btn-primary dropdown-text" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改</a>
            </div>
            <div class="btn-group">
                <a id="NF-delete" class="btn btn-primary dropdown-text" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除</a>
            </div>
        </div>
        <div>
            <table class="form search" style="width:65%">
                <tr>
                    <td class="formTitle">年份：</td>
                    <td class="formValue">
                        <select id="Year" class="form-control">
                            <option value="-1">===请选择===</option>
                        </select>
                    </td>
                    <td class="formTitle">月份：</td>
                    <td class="formValue">
                        <select id="Month" class="form-control">
                            <option value="-1">===请选择===</option>
                        </select>
                    </td>
                    <td class="formTitle"></td>
                    <td class="formTitle">
                        <div class="input-group">
                            <input type="text" id="zls" class="form-control" placeholder="治疗师姓名" />
                            <span class="input-group-btn">
                                <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                            </span>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="gridPanel" id="tabGrid">
        <table id="HisgridList" rel="tabGrid"></table>
        <div id="gridPager"></div>
    </div>
</form>
